export default {
	validEmail(email) {
	  const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	  return reg.test(email)
	},
	validURL(url) {
	  const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
	  return reg.test(url)
	},
	objToUrl(params) {
	  let result = ''
	  for (const propName of Object.keys(params)) {
	    const value = params[propName];
	    var part = encodeURIComponent(propName) + "=";
	    if (value !== null && value !== "" && typeof (value) !== "undefined") {
	      if (typeof value === 'object') {
	        for (const key of Object.keys(value)) {
	          if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
	            let params = propName + '[' + key + ']';
	            var subPart = encodeURIComponent(params) + "=";
	            result += subPart + encodeURIComponent(value[key]) + "&";
	          }
	        }
	      } else {
	        result += part + encodeURIComponent(value) + "&";
	      }
	    }
	  }
	  return result
	},
	getQueryObject(url) {
	  url = url == null ? window.location.href : url
	  const search = url.substring(url.lastIndexOf('?') + 1)
	  const obj = {}
	  const reg = /([^?&=]+)=([^?&=]*)/g
	  search.replace(reg, (rs, $1, $2) => {
	    const name = decodeURIComponent($1)
	    let val = decodeURIComponent($2)
	    val = String(val)
	    obj[name] = val
	    return rs
	  })
	  return obj
	},
	isHttp(url) {
	  return url.indexOf('http://') !== -1 || url.indexOf('https://') !== -1
	},
	parseParamsUrl(url) {
		let paramUrl = url.split("?")[1];
		let params = paramUrl.split("&");
		let paramObj = {};
		params.forEach(item => {
			let itemSplit = item.split("=");
			paramObj[itemSplit[0]] = itemSplit[1];
		})
		return paramObj;
	}
}
